package com.example.app.pages.main.home.addNew.addRecord.MyModalBottomSheetRelationPicker

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.width
import androidx.compose.material3.ListItemDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.example.app.components.MyCheckBox.MyCustomCheckBox
import com.example.app.components.MyCheckBox.MyCustomCheckBoxItem
import com.example.app.components.MyDivider.MyDivider
import com.example.app.components.MyDivider.MyDividerDirection
import com.example.app.components.MyField.MyField
import com.example.app.components.MyIcon.MyCircleCancelIcon
import com.example.app.components.MyIcon.MySelectorIcon
import com.example.app.components.MyListItem.MyListItem
import com.example.app.components.MySpacer.MySpacer
import com.example.app.components.MyText.MyText
import com.example.app.data.bean.routeAddAccount.AccountRelationPeople
import com.example.app.ui.theme.my_border_color

@Composable
fun AccountRelationPeopleItem(
        accountRelationPeople: AccountRelationPeople,
        editSelectedCurRelationPeopleHandler: (accountRelationPeople: AccountRelationPeople) -> Unit,
        deleteRelationPeopleItemHandler: (accountRelationPeople: AccountRelationPeople) -> Unit,
        isEdit: MutableState<Boolean>,
        checkHandler: (bool: Boolean) -> Unit = {},
        myCustomCheckBoxItem:MyCustomCheckBoxItem
) {
    var _isEdit by remember {
        isEdit
    }
    Column(
        modifier = Modifier
            .background(MaterialTheme.colorScheme.surface)
            .clickable {
                //删除
                if (_isEdit) {
                    deleteRelationPeopleItemHandler(accountRelationPeople)
                }
                //编辑
                else {
                    editSelectedCurRelationPeopleHandler(accountRelationPeople)
                }
            }
    ) {
        MyListItem(
            hasWrap = false,
            headlineContent = {
                MyField(labelContent = {
                    Row(
                        horizontalArrangement = Arrangement.Start,
                        verticalAlignment = Alignment.CenterVertically
                    ) {
                        if (_isEdit) {
                            MyCustomCheckBox(checkHandler,myCustomCheckBoxItem)
                            MySpacer(modifier = Modifier.width(4.dp))
                        }
                        MyText(text = accountRelationPeople.Title!!)
                    }
                },
                    valueContent = {
                        if (_isEdit) {
                            MyCircleCancelIcon(tint = MaterialTheme.colorScheme.primary)
                        } else {
                            MySelectorIcon()
                        }
                    })
            },
            //containerColor的颜色，白色
            colors = ListItemDefaults.colors(
                containerColor = Color.Transparent
            )
        )
        MyDivider(
            myDividerDirection = MyDividerDirection.HOR,
            color = my_border_color
        )
    }
}
